package com.xframe.xdal.core.model.es;

import com.xframe.xdal.core.model.ConditionValue;
import com.xframe.xdal.core.util.StringUtil;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;

public class TermQueryBuilder implements IQueryBuilder {


    protected String esQueryBuildArgs;


    public TermQueryBuilder(String esQueryBuildArgs){
        this.esQueryBuildArgs = esQueryBuildArgs;
    }

    @Override
    public QueryBuilder builder(ConditionValue conditionValue) {


        QueryBuilder queryBuilder = null;
        if(StringUtil.isEmpty(esQueryBuildArgs)) {
           queryBuilder = QueryBuilders.termQuery(conditionValue.getFieldName() + ".keyword",
                   conditionValue.getValByEs());
        }else {
            queryBuilder = QueryBuilders.termQuery(conditionValue.getFieldName(),
                    conditionValue.getValByEs());
        }
        return queryBuilder;
    }
}
